package org.zpmis.api.http;

import org.zpmis.api.business.LabelWebService;
import org.zpmis.common.base.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.domain.label.qo.LabelQo;
import org.zpmis.domain.label.qo.QueryLabelListQo;

import javax.annotation.Resource;

/**
* created with CodeGenerator
* description:
* @author  Yang
* date: 2021-11-18
* time: 15:28:30
*/
@RestController
@RequestMapping("/label")
@Slf4j
public class LabelController extends BaseController{

    @Resource
    private LabelWebService labelWebService;


    /**
     * 新增标签卷
     * @param labelQo
     * @return
     */
    @PostMapping("/addLabel")
    public PlatformResult addLabel(@RequestBody LabelQo labelQo){
        try {
            labelWebService.addLabel(labelQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[LabelController]---addLabel BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[LabelController]---addLabel Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 修改标签卷
     * @param labelQo
     * @return
     */
    @PostMapping("/editLabel")
    public PlatformResult editLabel(@RequestBody LabelQo labelQo){
        try {
            labelWebService.editLabel(labelQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[LabelController]---editLabel BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[LabelController]---editLabel Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 获取标签卷详情
     * @param labelQo
     * @return
     */
    @PostMapping("/labelDetail")
    public PlatformResult labelDetail(@RequestBody LabelQo labelQo){
        try {
            return PlatformResult.success(labelWebService.labelDetail(labelQo));
        } catch (BusinessException e) {
            log.error("[LabelController]---labelDetail BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[LabelController]---labelDetail Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 删除标签卷
     * @param labelQo
     * @return
     */
    @PostMapping("/deleteLabel")
    public PlatformResult deleteLabel(@RequestBody LabelQo labelQo){
        try {
            labelWebService.deleteLabel(labelQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[LabelController]---deleteLabel BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[LabelController]---deleteLabel Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 标签列表查询
     * @param queryLabelListQo
     * @return
     */
    @PostMapping("/labelList")
    public PlatformResult labelList(@RequestBody QueryLabelListQo queryLabelListQo){
        try {

            return PlatformResult.success(labelWebService.labelList(queryLabelListQo));
        } catch (BusinessException e) {
            log.error("[LabelController]---labelList BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[LabelController]---labelList Exception:",e);
            return PlatformResult.failure();
        }
    }
    /**
     * 下载标签列表
     * @param queryLabelListQo
     * @return
     */
    @GetMapping("/downLoadLabelList")
    public void downLoadLabelList(QueryLabelListQo queryLabelListQo){
        try {
            labelWebService.writeExcelLabel(queryLabelListQo);
        } catch (BusinessException e) {
            log.error("[LabelController]---downLoadLabelList BusinessException:",e);
        } catch (Exception e) {
            log.error("[LabelController]---downLoadLabelList Exception:",e);
        }
    }
}
